﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Should.Fluent;

namespace Is.Test
{
    [TestClass]
    public class IsStringExtensionsTest
    {
        [TestMethod]
        public void Test_IsContain()
        {
            "alma".Is().Contains("l").Should().Be.True();
            "alma".Is().Contains("lm").Should().Be.True();
            "alma".Is().Contains("lma").Should().Be.True();
            "alma".Is().Contains("o").Should().Be.False();
            "alma".Is().Contains("ho").Should().Be.False();
            "alma".Is().Contains("olma").Should().Be.False();
            "alma".Is().Contains("almak").Should().Be.False();
            "alma".Is().Contains(string.Empty).Should().Be.False(); //// TODO !
            string.Empty.Is().Contains("a").Should().Be.False();
            string.Empty.Is().Contains(string.Empty).Should().Be.True();

            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => "alma".Is().Contains(null));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => string.Empty.Is().Contains(null));

            string nullstring = null;
            //// TODO ?future
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullstring.Is().Contains(string.Empty));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullstring.Is().Contains("a"));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullstring.Is().Contains(null));
        }

        [TestMethod]
        public void Test_IsStartWith()
        {
            "alma".Is().StartsWith("a").Should().Be.True();
            "alma".Is().StartsWith("al").Should().Be.True();
            "alma".Is().StartsWith("alm").Should().Be.True();
            "alma".Is().StartsWith("alma").Should().Be.True();
            "alma".Is().StartsWith("almak").Should().Be.False();
            "alma".Is().StartsWith("k").Should().Be.False();
            "alma".Is().StartsWith(string.Empty).Should().Be.False(); //// TODO !
            string.Empty.Is().StartsWith("a").Should().Be.False();
            string.Empty.Is().StartsWith(string.Empty).Should().Be.True();

            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => "alma".Is().StartsWith(null));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => string.Empty.Is().StartsWith(null));

            string nullstring = null;
            //// TODO ?future
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullstring.Is().StartsWith(string.Empty));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullstring.Is().StartsWith("a"));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullstring.Is().StartsWith(null));
        }

        [TestMethod]
        public void Test_IsEndWith()
        {
            "alma".Is().EndsWith("a").Should().Be.True();
            "alma".Is().EndsWith("ma").Should().Be.True();
            "alma".Is().EndsWith("lma").Should().Be.True();
            "alma".Is().EndsWith("alma").Should().Be.True();
            "alma".Is().EndsWith("almak").Should().Be.False();
            "alma".Is().EndsWith("k").Should().Be.False();
            "alma".Is().EndsWith(string.Empty).Should().Be.False(); //// TODO !
            string.Empty.Is().EndsWith("a").Should().Be.False();
            string.Empty.Is().EndsWith(string.Empty).Should().Be.True();

            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => "alma".Is().EndsWith(null));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => string.Empty.Is().EndsWith(null));

            string nullstring = null;
            //// TODO ?future
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullstring.Is().EndsWith(string.Empty));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullstring.Is().EndsWith("a"));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullstring.Is().EndsWith(null));
        }

        [TestMethod]
        public void Test_IsNull()
        {
            string nullstring = null;
            nullstring.Is().Null().Should().Be.True();
            "lam".Is().Null().Should().Be.False();
        }

        [TestMethod]
        public void Test_IsEmpty()
        {
            string.Empty.Is().Empty().Should().Be.True();
            "lam".Is().Empty().Should().Be.False();

            string nullstring = null;
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullstring.Is().Empty());
        }

        [TestMethod]
        public void Test_IsNullOrEmpty()
        {
            string nullstring = null;
            nullstring.Is().NullOrEmpty().Should().Be.True();
            string.Empty.Is().NullOrEmpty().Should().Be.True();
            "lam".Is().NullOrEmpty().Should().Be.False();
        }

        [TestMethod]
        public void Test_IsGreaterThan()
        {
            "b".Is().GreaterThan("a").Should().Be.True();
            "a".Is().GreaterThan("b").Should().Be.False();
            "a".Is().GreaterThan("a").Should().Be.False();
            "a".Is().GreaterThan("A").Should().Be.False();
            "a".Is().GreaterThan("A", StringComparer.Ordinal).Should().Be.True();
            "a".Is().GreaterThan("A", StringComparer.OrdinalIgnoreCase).Should().Be.False();

            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => "a".Is().GreaterThan(null));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => "a".Is().GreaterThanOrEqualTo("A", null));

            string nullObject = null;
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullObject.Is().GreaterThan("a"));
        }

        [TestMethod]
        public void Test_IsGreaterThanOrEqualTo()
        {
            "b".Is().GreaterThanOrEqualTo("a").Should().Be.True();
            "a".Is().GreaterThanOrEqualTo("b").Should().Be.False();
            "a".Is().GreaterThanOrEqualTo("a").Should().Be.True();
            "a".Is().GreaterThanOrEqualTo("A").Should().Be.False();
            "a".Is().GreaterThanOrEqualTo("A", StringComparer.Ordinal).Should().Be.True();
            "a".Is().GreaterThanOrEqualTo("A", StringComparer.OrdinalIgnoreCase).Should().Be.True();

            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => "a".Is().GreaterThanOrEqualTo(null));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => "a".Is().GreaterThanOrEqualTo("A", null));

            string nullObject = null;
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullObject.Is().GreaterThanOrEqualTo("a"));
        }

        [TestMethod]
        public void Test_IsLessThan()
        {
            "a".Is().LessThan("b").Should().Be.True();
            "b".Is().LessThan("a").Should().Be.False();
            "A".Is().LessThan("a", StringComparer.Ordinal).Should().Be.True();
            "A".Is().LessThan("a", StringComparer.OrdinalIgnoreCase).Should().Be.False();

            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => "a".Is().LessThan(null));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => "a".Is().LessThan("A", null));

            string nullObject = null;
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullObject.Is().LessThan("a"));
        }

        [TestMethod]
        public void Test_IsLessThanOrEqualTo()
        {
            "b".Is().LessThanOrEqualTo("a").Should().Be.False();
            "a".Is().LessThanOrEqualTo("b").Should().Be.True();
            "a".Is().LessThanOrEqualTo("a").Should().Be.True();
            "a".Is().LessThanOrEqualTo("A").Should().Be.True();
            "a".Is().LessThanOrEqualTo("A", StringComparer.Ordinal).Should().Be.False();
            "a".Is().LessThanOrEqualTo("A", StringComparer.OrdinalIgnoreCase).Should().Be.True();

            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => "a".Is().LessThanOrEqualTo(null));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => "a".Is().LessThanOrEqualTo("A", null));

            string nullObject = null;
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullObject.Is().LessThanOrEqualTo("a"));
        }
    }
}
